package temp;

public class 将字段声明为表中字段 {

    public static void main(String[] args) {

        String tableName = "product_type";

        String s = "" +
                "\n" +
                "    //父节点id\n" +
                "    private String pid;\n" +
                "\n" +
                "    //层级,根节点层级为0\n" +
                "    private Integer hierarchy;\n" +
                "\n" +
                "    //名称\n" +
                "    private String name;\n";
        String[] split = s.split("\n");

        StringBuilder builder = new StringBuilder();

        for (String line : split) {
            line = line.trim();
            String n = "";
            if (line.startsWith("private")) {
                line = line.replace("private ", "").replace(";", "").trim();
                String type = "";
                String name = "";
                if (line.startsWith("String")) {
                    type = "varchar(100)";
                    name = line.replace("String", "");
                } else if (line.startsWith("Integer")) {
                    type = "int(11)";
                    name = line.replace("Integer", "");
                } else if (line.startsWith("Date")) {
                    type = "datetime";
                    name = line.replace("Date", "");
                } else if (line.startsWith("Boolean")) {
                    type = "tinyint(1)";
                    n = name = line.replace("Boolean", "");
                } else if (line.startsWith("Double")) {
                    type = "double";
                    name = line.replace("Double", "");
                }

                name = name.trim();
                char[] chars = name.toCharArray();

                StringBuilder b = new StringBuilder();

                for (char aChar : chars) {

                    if (aChar <= 90) {
                        b.append("_").append((char) (aChar + 32));
                    } else {
                        b.append(aChar);
                    }
                }

                name = b.toString();

                builder.append("ALTER TABLE ").append(tableName).append(" ADD ").append(name).append(" ").append(type).append(";\n");
/*

                String template = "<el-col :span=\"4\">\n" +
                        "              <el-checkbox @change=\"changeOrderRequired\" v-model=\"orderRequireItems.${name}\">${t}</el-checkbox>\n" +
                        "            </el-col>";

                builder.append(template.replace("${name}", n.trim()).replace("${t}", t));
*/

            }

        }

        System.out.println(builder.toString());

    }

}
